<template>

	<view class="main">
		<u-navbar :fixed="false" title="缴费确认" @rightClick="rightClick" :autoBack="true"></u-navbar>






		<view class=" column_c">

			<view class="card-content" style="margin-top: 30rpx;">

				<view class="hzxx">患者信息</view>
				<u-line margin="30rpx 0 30rpx 0"></u-line>


				<view class="row_a_c space-between item-a">
					<text class="clinic">姓名</text>
					<text class="status  center">{{InfosData.order.name}}</text>
				</view>

				<view class="row_a_c space-between item-a">
					<text class="clinic">号码</text>
					<text class="status  center">{{InfosData.order.id}}</text>
				</view>

				<view class="row_a_c space-between item-a">
					<text class="clinic">联系电话</text>
					<text class="status  center">{{InfosData.order.phone}}</text>
				</view>

			</view>

			<view class="card-content">

				<view class="hzxx">消费信息</view>
				<u-line margin="30rpx 0 30rpx 0"></u-line>



				<u--form labelWidth="100" :model="formData" :rules="rules" ref="uForm">
					<u-form-item label="交易金额" prop="amount" borderBottom>
						<u--input placeholder="请输入" v-model="formData.amount" border="none"></u--input>
					</u-form-item>

					<u-form-item label="支付方式" prop="payment_way" borderBottom>
						<u--input placeholder="请输入" v-model="formData.payment_way" border="none"></u--input>
					</u-form-item>

			

					<u-form-item label="备注" borderBottom>
						<u--input placeholder="请输入" v-model="formData.remark" border="none"></u--input>
					</u-form-item>

					<u-form-item label="图片" prop="avatar" borderBottom>
						<u-upload :fileList="fileList1" @afterRead="afterRead" @delete="deletePic" name="1" multiple :maxCount="9"></u-upload>
					</u-form-item>

				</u--form>

			</view>

			<view style="width: 690rpx;">
				<u-button @click="submit()" :custom-style="{ backgroundColor: '#27CCBB', marginTop:'100rpx',marginBottom: '50rpx',color: '#fff', borderRadius: '40rpx', height:'80rpx'}" text="保 存"></u-button>
			</view>

		</view>




	</view>

</template>

<script>
	import api_appointment from '@/api/appointment.js';

	export default {
		components: {},
		async onLoad(option) {
			this.order = option.id;
		},

		async onShow() {
			this.access_token = uni.getStorageSync('access_token');
			if (!this.access_token) {
				uni.navigateTo({
					url: '/pages/auth/login'
				});
			} else {
				this.getOrderProcessFuc(); //查看流程

			}
		},
		data() {
			return {
				fileList1: [],
				order: null,
				value: null,
				InfosData: null,
				formData: {
					amount: null,
					payment_way: null,
					attachment: null,
					remark: null,
				},
				rules: {
					amount: {
						type: 'string',
						required: true,
						message: '请输入金额',
						trigger: ['blur', 'change']
					},
					payment_way: {
						type: 'string',
						required: true,
						message: '请输入支付方式',
						trigger: ['blur', 'change']
					},
				},

			};
		},

		onReady() {
			// 如果需要兼容微信小程序，并且校验规则中含有方法等，只能通过setRules方法设置规则
			this.$refs.uForm.setRules(this.rules)
		},
		methods: {


			submit() {
				this.$refs.uForm.validate().then(res => {
					this.confirmPaymentFuc();
				}).catch(errors => {
					uni.$u.toast('请检查填写信息')
				})

			},

			toUrlInfo() {
				uni.navigateTo({
					url: '/pages/patient/treatment-procedure?id=' + this.order
				});
			},

			// 确认缴费
			async confirmPaymentFuc() {

				var per = {
					order: this.order,
				}

				per.payment_way = this.formData.payment_way
				per.amount = this.formData.amount




				if (this.formData.remark) {
					per.remark = this.formData.remark
				}

				if (this.fileList1.length > 0) {
					per.attachment = this.fileList1.map(item => item.url);
				}


				const res = await api_appointment.confirmPayment(per);
				if (res.code == 1) {
					this.$util.msg(res.message);
					this.toUrlInfo();
				} else {
					this.$util.msg(res.message);
					return;
				}
			},


			deletePic(event) {
				this[`fileList${event.name}`].splice(event.index, 1)
			},
			// 新增图片
			async afterRead(event) {
				// 当设置 multiple 为 true 时, file 为数组格式，否则为对象格式
				let lists = [].concat(event.file)
				let fileListLen = this[`fileList${event.name}`].length
				lists.map((item) => {
					this[`fileList${event.name}`].push({
						...item,
						status: 'uploading',
						message: '上传中'
					})
				})
				for (let i = 0; i < lists.length; i++) {
					const result = await this.uploadFilePromise(lists[i].url)

					let item = this[`fileList${event.name}`][fileListLen]
					this[`fileList${event.name}`].splice(fileListLen, 1, Object.assign(item, {
						status: 'success',
						message: '',
						url: result
					}))
					fileListLen++
				}
			},
			uploadFilePromise(url) {
				return new Promise((resolve, reject) => {
					let a = uni.uploadFile({
						url: 'http://192.168.88.237:8788/api/upload/file', // 仅为示例，非真实的接口地址
						filePath: url,
						name: 'file',
						formData: {
							type: 'image'
						},
						success: (res) => {
							setTimeout(() => {
								const parsedData = JSON.parse(res.data);
								resolve(parsedData.data.url)
							}, 1000)
						}
					});
				})
			},

			//查看流程
			async getOrderProcessFuc() {
				var per = {
					order: this.order
				}
				const res = await api_appointment.getOrderProcess(per);
				if (res.code == 1) {
					this.InfosData = res.data;
					console.log('hhhhhhhhhhhhhhh', this.InfosData);
				} else {
					this.$util.msg(res.message);
					return;
				}
			},

		}
	};
</script>

<style scoped lang="scss">
	.main {
		background: #FAFAFA;
		height: 100vh;

		// padding: 32rpx;
	}

	.bit {
		padding: 32rpx;
	}

	.but {

		width: 290rpx;
		height: 60rpx;
		background: #FFFFFF;
		border-radius: 50rpx 50rpx 50rpx 50rpx;
		padding: 0 30rpx;
	}

	.time {
		font-weight: 400;
		font-size: 28rpx;
		color: #7F7F7F;
	}

	.xltb {
		width: 32rpx;
		height: 32rpx;
	}


	.container {
		padding: 0;
	}

	.card {
		background-color: #fff;
		border-radius: 8px;
		box-shadow: 0 2px 10px rgba(0, 0, 0, 0.1);
		margin-bottom: 20px;
	}

	.card-header {
		display: flex;
		justify-content: space-between;
		padding: 10px;
		border-bottom: 1px solid #f0f0f0;
	}

	.item-a {
		margin-bottom: 32rpx;
	}

	.status {
		font-weight: 400;
		font-size: 28rpx;
		color: rgba(0, 0, 0, 0.85);
	}

	.clinic {
		font-weight: 400;
		font-size: 28rpx;
		color: rgba(0, 0, 0, 0.6);
	}


	.cancelled {
		color: #f44336;
	}

	.card-content {
		width: 686rpx;
		min-height: 200rpx;
		background: #FFFFFF;
		box-shadow: 0rpx 0rpx 8rpx -2rpx rgba(0, 0, 0, 0.04), 0rpx 0rpx 10rpx 0rpx rgba(0, 0, 0, 0.03), 0rpx 0rpx 20rpx 0rpx rgba(0, 0, 0, 0.02);
		border-radius: 20rpx 20rpx 20rpx 20rpx;
		padding: 32rpx 32rpx 0 32rpx;
		margin-bottom: 20rpx;

	}



	.name {
		font-weight: 400;
		font-size: 24rpx;
		color: rgba(0, 0, 0, 0.6);
		margin-bottom: 12rpx;

	}

	.time {
		font-weight: 400;
		font-size: 24rpx;
		color: rgba(0, 0, 0, 0.6);
		margin-bottom: 12rpx;
	}



	.appointment-info {
		margin-top: 20rpx;
	}

	.hzxx {
		font-weight: 600;
		font-size: 28rpx;
		color: rgba(0, 0, 0, 0.85);
	}

	.ysh {
		width: 160rpx;
		height: 160rpx;
		margin-left: 10rpx;
	}

	::v-deep .u-input__content__field-wrapper__field {
		background: #FFFFFF !important;
	}
</style>